import * as robotModel from '../../models/robot';
import { EmptyException, ValidException } from '../../helps/exception';

/**
 * 获取夜间模式
 * @param {*} {robot_id}
 * @return {*} {is_open, start_time, end_time}
 */
export function* getNight({ robot_id }) {
  if (!robot_id) throw ValidException('Robot参数错误');
  let robot = yield robotModel.get(robot_id);
  if (!robot) throw EmptyException('Robot不存在');
  return {
    is_open: robot.night_status,
    start_time: robot.night_start_time,
    end_time: robot.night_end_time,
  };
}

/**
 * 获取防沉迷
 * @param {*} {robot_id}
 * @return {*} {is_open, duration}
 */
export function* getAntiAddiction({ robot_id }) {
  if (!robot_id) throw ValidException('Robot参数错误');
  let robot = yield robotModel.get(robot_id);
  if (!robot) throw EmptyException('Robot不存在');
  return {
    is_open: robot.anti_addiction_status,
    duration: robot.anti_addiction_duration,
  };
}
